package com.lagou.framework.config;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

import java.io.File;
import java.util.Objects;

/**
 * Server.xml 解析器
 *
 * @author srh
 * @date 2020/04/03
 **/
@Data
public class XmlServerResolver {

    public XmlServerConfig read(String path) throws Exception {
        if (StringUtils.isBlank(path)) {
            throw new NullPointerException();
        }
        return read(new File(path));
    }

    public XmlServerConfig read(File source) throws Exception {
        if (Objects.isNull(source)) {
            throw new NullPointerException();
        }
        Serializer serializer = new Persister();
        return serializer.read(XmlServerConfig.class, source);
    }
}
